import 'package:casdon/modules/device/application/notification/device_discover_notifier.dart';
import 'package:casdon/modules/device/domain/states/device_discovery_state.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tuya_home_sdk_flutter/tuya_home_sdk_flutter.dart';

/// 设备发现状态Provider
final deviceDiscoveryProvider =
    StateNotifierProvider.autoDispose<
      DeviceDiscoveryNotifier,
      DeviceDiscoveryState
    >((ref) {
      final notifier = DeviceDiscoveryNotifier();
      return notifier;
    });

/// 设备列表Provider
final discoveredDevicesProvider =
    Provider.autoDispose<List<ThingSmartDeviceModel>>((ref) {
      return ref.watch(
        deviceDiscoveryProvider.select((state) => state.devices),
      );
    });

/// 搜索状态Provider
final isSearchingProvider = Provider.autoDispose<bool>((ref) {
  return ref.watch(
    deviceDiscoveryProvider.select((state) => state.isSearching),
  );
});

/// 错误状态Provider
final discoveryErrorProvider = Provider.autoDispose<String?>((ref) {
  return ref.watch(deviceDiscoveryProvider.select((state) => state.error));
});
